/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useEffect, useState } from 'react';
import { List, Row, Col } from 'antd';
import { getList } from '@/services/Other/Cov19';
import { useSelector } from 'umi';
import type { ListItem } from '../cov19';
import moment from 'moment';

interface CovRecordsProps {
  current: 'imp' | 'records' | string;
}

const CovRecords: React.FC<CovRecordsProps> = ({ current }) => {
  const [list, setList] = useState<ListItem[]>([]);

  const { userInfo = {} } = useSelector(({ user }) => user?.currentUser);
  const { name } = userInfo;

  useEffect(() => {
    if (current === 'records') {
      getList({ name, operate_time: moment().format('YYYY-MM-DD HH:mm:ss') }).then(
        (res: ListItem[]) => {
          setList(res);
        },
      );
    }
  }, [current]);

  return (
    <List
      dataSource={list}
      renderItem={(item) => (
        <List.Item key={item.id}>
          <Row style={{ width: '100%' }}>
            <Col xs={12} md={5}>
              {item.operate_time}
            </Col>
            <Col xs={12}>{item.name}上传疫情数据表</Col>
          </Row>
        </List.Item>
      )}
    />
  );
};

export default CovRecords;
